package com.iogogogo.tenant.repository;

import com.iogogogo.tenant.config.DataSourceBasedMultiTenantConnectionProviderImpl;
import com.iogogogo.tenant.config.base.BaseDao;
import com.iogogogo.tenant.pojo.entity.UserEntity;
import org.springframework.stereotype.Repository;

import java.time.LocalDateTime;
import java.util.List;

/**
 * Created by tao.zeng on 2021/8/8.
 */
@Repository
public class UserRepository extends BaseDao {

    public UserRepository(DataSourceBasedMultiTenantConnectionProviderImpl datasourceProvider) {
        super(datasourceProvider);
    }

    public List<UserEntity> findAll() {
        return getJdbcTemplate().query("select * from sys_user", (rs, rowNum) -> {
            UserEntity user = new UserEntity();
            user.setId(rs.getLong(1));
            user.setUsername(rs.getString(2));
            user.setPassword(rs.getString(3));
            user.setAddress(rs.getString(4));
            user.setBirthday(rs.getObject(5, LocalDateTime.class));
            return user;
        });
    }

    public UserEntity findById(Long userId) {
        return null;
    }
}
